﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Text;
using System.Windows.Forms;
using InkFx.WinControl.Core;
using InkFx.WinControl.Theme;
using InkFx.WinControl.Utils;
using Temp_20210321_AForm9.Properties;

namespace InkFx.WinControl
{
    /// <summary>
    /// 提供一个可用来创建其他控件的空控件。
    /// </summary>
    [ToolboxItem(false)]
    public class XIDEUserControl : System.Windows.Forms.UserControl
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        public XIDEUserControl()
        {
            SetStyle(Win32API.ControlStylesUAORSD, true);

            base.BorderStyle = System.Windows.Forms.BorderStyle.None;
            base.BackColor = Color.Transparent;
            base.ForeColor = SystemColors.ControlText;
            base.AutoScaleMode = AutoScaleMode.Dpi;
            base.AutoScaleDimensions = new SizeF(96F, 96F);
            base.DoubleBuffered = true;
        }


        #region  样 式 属 性 事 件

        /// <summary>
        /// 内部字段
        /// </summary>
        protected ThemeXIDEPanel m_Theme;

        /// <summary>
        /// 皮肤
        /// </summary>
        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Localizable(false)]
        public virtual ThemeXIDEPanel Theme
        {
            get
            {
                if (m_Theme == null)
                {
                    m_Theme = new ThemeXIDEPanel();
                    m_Theme.Skin = "Name";
                    m_Theme.XIDEPanel_ForeColor = Color.FromArgb(20, 20, 20);
                    m_Theme.XIDEPanel_BackColor = Color.Transparent;
                    m_Theme.XIDEPanel_BackColor_Active = Color.Transparent;
                    m_Theme.XIDEPanel_BorderColor = Color.FromArgb(152, 152, 152);
                    m_Theme.XIDEPanel_BorderColor_Active = Color.FromArgb(152, 152, 152);
                    m_Theme.XIDEPanel_HeadTop_V4 = new SkinBorderImage_V4(Resources.XIDEPanel_HeadTop_V4, 3, 0, 2, 2, FillStyle.Fill);
                    m_Theme.XIDEPanel_HeadBottom_V4 = new SkinBorderImage_V4(Resources.XIDEPanel_HeadBottom_V4, 0, 3, 2, 2, FillStyle.Fill);
                    m_Theme.XIDEPanel_HeadLeft_V4 = new SkinBorderImage_V4(Resources.XIDEPanel_HeadLeft_V4, 2, 2, 3, 0, FillStyle.Fill);
                    m_Theme.XIDEPanel_HeadRight_V4 = new SkinBorderImage_V4(Resources.XIDEPanel_HeadRight_V4, 2, 2, 0, 3, FillStyle.Fill);
                    m_Theme.XIDEGroup_Title_V4 = new SkinBorderImage_V4(Resources.XIDEGroup_Title_V4, 3, 0, 2, 2, FillStyle.Fill);
                    m_Theme.XIDEGroup_HeadTop_V4 = new SkinBorderImage_V4(Resources.XIDEGroup_HeadTop_V4, 3, 0, 2, 2, FillStyle.Fill);
                    m_Theme.XIDEGroup_HeadBottom_V4 = new SkinBorderImage_V4(Resources.XIDEGroup_HeadBottom_V4, 0, 3, 2, 2, FillStyle.Fill);
                    m_Theme.XIDEGroup_ButtonBack_V4 = new SkinBorderImage_V4(Resources.XIDEGroup_ButtonBack_V4, 3, 0, 2, 2, FillStyle.Fill);
                    m_Theme.XIDEGroup_Button_V6 = new SkinImage_V6 { FileBytes = ImageHelper.GetImageBytes(Resources.XIDEGroup_Button_V6) };
                    m_Theme.XIDETipForm_Area_V10 = new SkinImage_V10 { FileBytes = ImageHelper.GetImageBytes(Resources.XIDETipForm_Area_V10) };
                    m_Theme.XIDEFloatForm_BackColor = Color.FromArgb(240, 240, 240);
                    m_Theme.XIDEFloatForm_BorderColor = Color.FromArgb(152, 152, 152);
                }
                return m_Theme;
            }
            set
            {
                if (m_Theme != null && m_Theme != value) { m_Theme.Dispose(); }
                m_Theme = value;
            }
        }

        #endregion

        #region  字 段 属 性


        /// <summary>
        /// 内部字段
        /// </summary>
        protected bool m_BorderVisible = true;
        /// <summary>
        /// 内部字段
        /// </summary>
        protected Color m_BorderColor = Color.Transparent;


        /// <summary>
        /// 边框颜色, 如果为 Transparent 则使用 Theme 的边框颜色
        /// </summary>
        [CategorySkinTheme, Browsable(true), DefaultValue(typeof(Color), "Transparent"), Description("边框颜色, 如果为 Transparent 则使用 Theme 的边框颜色")]
        public virtual Color BorderColor
        {
            get { return m_BorderColor; }
            set { var color = this.BorderColor; /*if (value.A < 255) { value = Color.FromArgb(255, value.R, value.G, value.B); }*/ if (color.A != value.A || color.R != value.R || color.G != value.G || color.B != value.B) { m_BorderColor = value; this.Invalidate(); } }
        }
        /// <summary>
        /// 是否显示边框
        /// </summary>
        [CategorySkinTheme, Browsable(true), DefaultValue(true), Description("是否显示边框")]
        public virtual bool BorderVisible
        {
            get { return m_BorderVisible; }
            set { m_BorderVisible = value; this.Invalidate(); }
        }
        /// <summary>
        /// 获取或设置用户控件的边框样式。
        /// </summary>
        [CategorySkinTheme, Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public new virtual System.Windows.Forms.BorderStyle BorderStyle
        {
            get
            {
                if (base.BorderStyle != System.Windows.Forms.BorderStyle.None) { base.BorderStyle = System.Windows.Forms.BorderStyle.None; }
                return System.Windows.Forms.BorderStyle.None;
            }
            set
            {
                base.BorderStyle = System.Windows.Forms.BorderStyle.None;
                this.UpdateStyles();
            }
        }




        #endregion


        /// <summary>
        /// 引发 System.Windows.Forms.Control.HandleCreated 事件。
        /// </summary>
        /// <param name="e">包含事件数据的 System.EventArgs。</param>
        protected override void OnHandleCreated(EventArgs e)
        {
            base.OnHandleCreated(e);
        }
        /// <summary>
        /// 释放由 System.Windows.Forms.Control 和它的子控件占用的非托管资源，另外还可以释放托管资源。
        /// </summary>
        /// <param name="disposing">为 true 则释放托管资源和非托管资源；为 false 则仅释放非托管资源。</param>
        protected override void Dispose(bool disposing)
        {
            try
            {
                base.Dispose(disposing);
                if (m_Theme != null) { m_Theme.Dispose(); m_Theme = null; }
            }
            catch (Exception ex) { Tools.LogWarn2(ex, "可忽略的偶发错误"); }
        }
        /// <summary>
        /// 引发 System.Windows.Forms.Control.GotFocus 事件。
        /// </summary>
        /// <param name="e">包含事件数据的 System.EventArgs。</param>
        protected override void OnGotFocus(EventArgs e)
        {
            base.OnGotFocus(e);
        }
        /// <summary>
        /// 引发 System.Windows.Forms.Control.LostFocus 事件。
        /// </summary>
        /// <param name="e">包含事件数据的 System.EventArgs。</param>
        protected override void OnLostFocus(EventArgs e)
        {
            base.OnLostFocus(e);
        }


    }
}
